﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entity;
using BAL;
using Common;

namespace Web
{
    public partial class PostCognitiveLevel : System.Web.UI.Page
    {
        private int editid = 0;
        private int delid = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!UserValidate.CheckLogin(this.Request, "MasterQuesType"))
            {
                Response.Write("<script type=\"text/javascript\">top.location.href='login.aspx';</script>");
                Response.Redirect("login.aspx");
                Response.End();
            }

            if (Request.QueryString["editid"] != null)
            {
                editid = Convert.ToInt32(Request.QueryString["editid"].Trim());
            }
            if (Request.QueryString["delid"] != null)
            {
                delid = Convert.ToInt32(Request.QueryString["delid"].Trim());
            }
            if (!IsPostBack)
            {
                if (editid > 0)
                {
                    CognitiveLevelInfo CognitiveLevelInfo = new CognitiveLevelInfo();
                    CognitiveLevelInfo = CognitiveLevel.GetSingleInfo(editid);
                    CognitiveLevelName.Text = CognitiveLevelInfo.Name.ToString();
                    CognitiveLevelKeyword.Text = CognitiveLevelInfo.Keyword;
                }
                if (delid > 0)
                {
                    CognitiveLevel.DelInfo(delid);
                    Response.Redirect("admininfo.aspx");
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (CognitiveLevelName.Text.Trim() != "" || CognitiveLevelKeyword.Text.Trim() != "")
            {
                    CognitiveLevelInfo CognitiveLevelInfo = new CognitiveLevelInfo();
                    if (editid > 0)
                    {
                        CognitiveLevelInfo = CognitiveLevel.GetSingleInfo(editid);
                    }
                    CognitiveLevelInfo.Name = CognitiveLevelName.Text.Trim();
                    CognitiveLevelInfo.Keyword = CognitiveLevelKeyword.Text.Trim();
                    if (editid > 0)
                    {
                        if (CognitiveLevel.CheckCognitiveLevelExistByKeyword(CognitiveLevelInfo.Keyword, editid))
                        {
                            Utility.ShowJsAlert("关键字已存在", this);
                        }
                        else
                        {
                            CognitiveLevel.Save(CognitiveLevelInfo);
                            Utility.ReloadTopPage(this);
                        }
                    }
                    else
                    {
                        if (CognitiveLevel.CheckCognitiveLevelExistByName(CognitiveLevelName.Text.Trim(), CognitiveLevelKeyword.Text.Trim()))
                        {
                            Utility.ShowJsAlert("该认知层次已经存在，或者关键字重复", this);
                        }
                        else
                        {
                            CognitiveLevel.Save(CognitiveLevelInfo);
                            Utility.ReloadTopPage(this);
                        }
                    }
            }
            else
            {
                Utility.ShowJsAlert("区分度名称和关键字不能为空！", this);
            }
        }
    }
}
